<%@ page contentType="text/html; charset=utf-8" language="java"
	import="java.sql.*" errorPage="" pageEncoding="utf-8"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<%@page import="iwpl.project.dao.*"%>
<%@page import="iwpl.project.entities.*"%>
<%@page import="iwpl.project.servlet.*"%>
<%@page import="iwpl.project.interfaces.*"%>
<%@page import="iwpl.project.entitymanagerhelper.*"%>

<%//String t = (String)session.getAttribute("Manage_Apartments");
//if(t!="active")
	//{response.sendRedirect("index.jsp");} %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link href="css/CommonCSS.css" rel="stylesheet" type="text/css" />
		<title>Manage Department</title>

		<script type="text/javascript">
	function Confirm(id) {
		var text = confirm("Are you sure ?");

		if (text == true) {
			//alert("Okey, Deleted !!!");
			location.href = "./servlet/Control_Department?delete=" + id;
		} else {
			alert("What ever !!!");
		}
	}
</script>
	</head>

	<body>
		<form id="form1" name="form1" method="get"
			action="./Insert_Departments.jsp">
			<table width="376" border="0">
				<tr>
					<td>
						<div align="center">
							<input type="submit" name="BtnAdd" value="Add" />
						</div>
					</td>
					<td>
						<div align="left">
							<input type="reset" name="BtnCancel" value="Cancel" />
						</div>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<div>
							<table width="100%" cellpadding="2" cellspacing="0" class="tblCommon">
								<tr class="trhead">
									<td>
										No
									</td>
									<td>
										ID
									</td>
									<td>
										Department Name
									</td>
									<td>
										Address
									</td>
									<td>
										Total Of Floor
									</td>
									<td>
										Phone
									</td>
									<td>
										Edit
									</td>
									<td>
										Delete
									</td>
								</tr>
								<%
									DepartmentsDAO dao = new DepartmentsDAO();
									List<Departments> list = dao.findAll();

									int i = 0;

									for (Iterator<Departments> it = list.iterator(); it.hasNext();) {
										Departments cate = (Departments) it.next();
										i++;

										if (i % 2 != 0) {
											out.println("<tr bgcolor=\"#CCFFFF\"><td>");
										} else {
											out.println("<tr bgcolor=\"#99CCCC\"><td>");
										}
										out.println(i + "</td>");
										out.println("<td>" + cate.getId() + "</td>");
										out.println("<td>" + cate.getDepartmentName() + "</td>");
										out.println("<td>" + cate.getAddress() + "</td>");
										out.println("<td>" + cate.getTotalOfFloor() + "</td>");
										out.println("<td>" + cate.getPhone() + "</td>");
										//out.println("<td>" + rsq.getString("CountID") + "</td></tr>");
										//out.println("<td>" + rs.getString("Status") + "</td></tr>");
										out.println("<td align=\"center\"><a href="
												+ "/DepartmentManage/Update_Departments.jsp?id="
												+ cate.getId().toString() + " /><img src="
												+ "./images/Edit.jpg" + " /></td>");
										/*out.println("<td><a href=" + "./servlet/myservlet?delete="
												+ rs.getString("CategoryID") + " /><img src="
												+ "./Pics/Delete.jpg" + " /></td></tr>");*/
										//out.println("<td><img src=\"./Pics/Delete.jpg\" onclick =\"Confirm()\"/></td></tr>");
										out.println("<td align=\"center\"><a href=javascript:Confirm('" + cate.getId()
												+ "') /><img src=" + "./images/Delete.jpg"
												+ " /></td></tr>");
									}
								%>
							</table>
						</div>
					</td>
				</tr>
			</table>
		</form>
	</body>
</html>